package org.jeecg.modules.system.model;

import lombok.Data;
import org.jeecg.enums.base.DepartPropertyEnum;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysTenant;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 部门表 存储树结构数据的实体类
 * <p>
 * 
 * @Author Steve
 * @Since 2019-01-22 
 */
@Data
public class SysDepartTreeModel implements Serializable{
	
    private static final long serialVersionUID = 1L;
    
    /** 对应SysDepart中的id字段,前端数据树中的key*/
    private String key;

    /** 对应SysDepart中的id字段,前端数据树中的value*/
    private String value;

    /** 对应depart_name字段,前端数据树中的title*/
    private String title;


    private boolean isLeaf;
    // 以下所有字段均与SysDepart相同
    
    private String id;

    private String parentId;

    private String parentIds;

    private String departName;
//
//    private String departNameEn;
//
//    private String departNameAbbr;
//
//    private Integer departOrder;

    private String departProperty;

//    private Object description;

//    private String orgType;

//    private String orgCode;

//    private String mobile;

//    private String address;

//    private String memo;

//    private String delFlag;

//    private String createBy;

//    private Date createTime;

//    private String updateBy;

//    private Date updateTime;

    private String type;

    private String projectId;

    private String floorId;

    private String roomId;

    private String tenantId;

    private List<SysDepartTreeModel> children = new ArrayList<>();

    /**
     * 将SysDepart对象转换成SysDepartTreeModel对象
     * @param sysDepart
     */
	public SysDepartTreeModel(SysDepart sysDepart) {
		this.key = sysDepart.getId();
        this.value = sysDepart.getId();
        this.title = sysDepart.getDepartName();
        this.id = sysDepart.getId();
        this.parentId = sysDepart.getParentId();
        this.departName = sysDepart.getDepartName();
//        this.departNameEn = sysDepart.getDepartNameEn();
//        this.departNameAbbr = sysDepart.getDepartNameAbbr();
//        this.departOrder = sysDepart.getDepartOrder();
        this.departProperty = sysDepart.getDepartProperty();
//        this.description = sysDepart.getDescription();
//        this.orgType = sysDepart.getOrgType();
//        this.orgCode = sysDepart.getOrgCode();
//        this.mobile = sysDepart.getMobile();
//        this.address = sysDepart.getAddress();
//        this.memo = sysDepart.getMemo();
//        this.delFlag = sysDepart.getDelFlag();
//        this.createBy = sysDepart.getCreateBy();
//        this.createTime = sysDepart.getCreateTime();
//        this.updateBy = sysDepart.getUpdateBy();
//        this.updateTime = sysDepart.getUpdateTime();
        this.type = sysDepart.getType();
        this.projectId = sysDepart.getProjectId();
        this.floorId = sysDepart.getFloorId();
        this.roomId = sysDepart.getRoomId();
        this.parentIds = sysDepart.getParentIds();
        this.tenantId = sysDepart.getTenantId();
    }

    public SysDepartTreeModel(SysTenant sysTenant) {
        this.key = sysTenant.getId();
        this.value = sysTenant.getId();
        this.title = sysTenant.getName();
        this.id = sysTenant.getId();
        this.parentId = sysTenant.getParentId();
        this.tenantId = sysTenant.getId();
        this.departProperty =  DepartPropertyEnum.DEPART_PROPERTY_CHANNEL.getCode();
        this.type = DepartPropertyEnum.DEPART_PROPERTY_CHANNEL.getCode();
        this.children = new ArrayList<>();
        this.isLeaf = false;
    }

    public SysDepartTreeModel() { }

    /**
     * 重写equals方法
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
			return true;
		}
        if (o == null || getClass() != o.getClass()) {
			return false;
		}
        SysDepartTreeModel model = (SysDepartTreeModel) o;
        return Objects.equals(id, model.id) &&
                Objects.equals(parentId, model.parentId) &&
//                Objects.equals(departName, model.departName) &&
//                Objects.equals(departNameEn, model.departNameEn) &&
//                Objects.equals(departNameAbbr, model.departNameAbbr) &&
//                Objects.equals(departOrder, model.departOrder) &&
                Objects.equals(departProperty,model.departProperty) &&
//                Objects.equals(description, model.description) &&
//                Objects.equals(orgType, model.orgType) &&
//                Objects.equals(orgCode, model.orgCode) &&
//                Objects.equals(mobile, model.mobile) &&
//                Objects.equals(address, model.address) &&
//                Objects.equals(memo, model.memo) &&
//                Objects.equals(delFlag, model.delFlag) &&
//                Objects.equals(createBy, model.createBy) &&
//                Objects.equals(createTime, model.createTime) &&
//                Objects.equals(updateBy, model.updateBy) &&
//                Objects.equals(updateTime, model.updateTime) &&
                Objects.equals(children, model.children);
    }
    
    /**
     * 重写hashCode方法
     */
    @Override
    public int hashCode() {

//        return Objects.hash(id, parentId, departName, departNameEn, departNameAbbr,
//        		departOrder, departProperty, description, orgType, orgCode, mobile, address,
//        		memo, delFlag, createBy, createTime, updateBy, updateTime,
//        		children);
        return Objects.hash(id, parentId, departProperty,children);
    }


    public boolean getIsLeaf() {
        return isLeaf;
    }

    public void setIsLeaf(boolean isLeaf) {
        this.isLeaf = isLeaf;
    }

    public String getDepartPropertyName() {
        return DepartPropertyEnum.getDesc(this.getDepartProperty());
    }
}
